import { defineStore } from "pinia";
// 查看任务详情
export const usetaskPass = defineStore({
  id: "task-pass",
  state: () => ({
    data: {
      planId: null,
      taskId: ""
    }
  })
});

// 添加明细数据传输
export const taskFormDetiall = defineStore({
  id: "taskFormDetiall",
  state: () => ({
    data: []
  }),
  actions: {
    DELETE_DATA(data) {
      this.data = this.data.filter(r => {
        if (r.uid) return r.uid !== data.uid;
        else return r.taskKeywordId !== data.taskKeywordId;
      });
    },
    UPDATE_DATA(data) {
      if (data.uid) {
        this.data = this.data.map(r => {
          if (r.uid === data.uid) {
            return { ...data };
          } else {
            return r;
          }
        });
      } else {
        this.data = this.data.map(r => {
          if (r.taskKeywordId === data.taskKeywordId) {
            return { ...data };
          } else {
            return r;
          }
        });
      }
    }
  }
});

export const taskTableDetiall = defineStore({
  id: "taskTableDetiall",
  state: () => ({
    data: []
  }),
  actions: {
    DELETE_DATA(data) {
      this.data = this.data.filter(r => {
        if (r.uid) return r.uid !== data.uid;
        else return r.taskKeywordId !== data.taskKeywordId;
      });
    },
    UPDATE_DATA(data) {
      if (data.uid) {
        this.data = this.data.map(r => {
          if (r.uid === data.uid) {
            return { ...data };
          } else {
            return r;
          }
        });
      } else {
        this.data = this.data.map(r => {
          if (r.taskKeywordId === data.taskKeywordId) {
            return { ...data };
          } else {
            return r;
          }
        });
      }
    }
  }
});

// 任务明细列表
export const TaskDetailList = defineStore({
  id: "TaskDetailList",
  state: () => ({
    data: [],
    total: 0,
    pageSize: 10,
    currentPage: 1,
    background: false
  })
});
